package com.weipt.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author weipt
 * @description 死信队列，基于fanout模式
 * 注意，进入死信队列的三个条件
 * 1、消息过期
 * 2、队列长度不够
 * 3、消息拒绝
 * @date 2024/1/16 22:23
 */
@Configuration
public class DeadFanoutQueueConfig {

    @Bean
    public FanoutExchange deadFanoutExchange(){
        return new FanoutExchange("fanout-dead-exchange-springboot", true, false);
    }

    /**
     *
     * String name,
     * boolean durable,
     * boolean exclusive,
     * boolean autoDelete,
     * @Nullable Map<String, Object> arguments
     */
    @Bean
    public Queue deadQueue(){
        return new Queue("dead-queue", true);
    }

    @Bean
    public Binding deadBinding(){
        return BindingBuilder.bind(deadQueue()).to(deadFanoutExchange());
    }


}
